package com.eagledata.project.business.vehicleInfo.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eagledata.framework.web.controller.BaseController;
import com.eagledata.framework.web.domain.Message;
import com.eagledata.framework.web.page.TableDataInfo;
import com.eagledata.project.business.vehicleInfo.domain.VehicleInfo;
import com.eagledata.project.business.vehicleInfo.service.IVehicleInfoService;

/**
 * 车辆 信息操作处理
 * 
 * @author eagledata
 * @date 2018-09-09
 */
@Controller
@RequestMapping("/business/vehicleInfo")
public class VehicleInfoController extends BaseController {
    private String prefix = "business/vehicleInfo";
	
	@Autowired
	private IVehicleInfoService vehicleInfoService;
	
	@RequestMapping()
	@RequiresPermissions("business:vehicleInfo:view")
	public String vehicleInfo() {
	    return prefix + "/vehicleInfo";
	}
	
	/**
	 * 查询车辆列表
	 */
	@RequiresPermissions("business:vehicleInfo:list")
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(VehicleInfo vehicleInfo) {
		startPage();
        List<VehicleInfo> list = vehicleInfoService.selectVehicleInfoList(vehicleInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增车辆
	 */
	@RequiresPermissions("business:vehicleInfo:add")
	@RequestMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 修改车辆
	 */
	@RequiresPermissions("business:vehicleInfo:edit")
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, Model model) {
		VehicleInfo vehicleInfo = vehicleInfoService.selectVehicleInfoById(id);
		model.addAttribute("vehicleInfo", vehicleInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存车辆
	 */
	@RequiresPermissions("business:vehicleInfo:save")
	@RequestMapping("/save")
	@ResponseBody
	public Message save(VehicleInfo vehicleInfo) {
		if (vehicleInfoService.saveVehicleInfo(vehicleInfo) > 0)
		{
			return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 删除车辆
	 */
	@RequiresPermissions("business:vehicleInfo:remove")
	@RequestMapping( "/remove/{id}")
	@ResponseBody
	public Message remove(@PathVariable("id") Long id) {
		if (vehicleInfoService.deleteVehicleInfoById(id) > 0)
		{
		    return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 批量删除车辆
	 */
	@RequiresPermissions("business:vehicleInfo:batchRemove")
	@RequestMapping( "/batchRemove")
	@ResponseBody
	public Message remove(@RequestParam("ids[]") Long[] ids) {
		int rows = vehicleInfoService.batchDeleteVehicleInfo(ids);
		if (rows > 0)
        {
            return Message.success();
        }
        return Message.error();
	}
	
}
